package com.zk.shop.servlet.user;

import com.zk.shop.entity.User;
import com.zk.shop.service.Impl.UserServiceImpl;
import com.zk.shop.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName UpdateUserServlet
 * @Description TODO
 * @Author 来永刚
 * @Date 2019/9/29 0029下午 7:21
 * @Version 1.0
 **/
@WebServlet("/UpdateUserServlet")
public class UpdateUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String userpwd = req.getParameter("userpwd");
        String address = req.getParameter("address");
        int userid = Integer.parseInt(req.getParameter("userid"));
        User user = new User(userid,username, userpwd, address);
        UserService userService = new UserServiceImpl();
        boolean flag = userService.updateUser(user);
        if (flag) {
            resp.getWriter().println("成功");
        } else {
            resp.getWriter().println("失败");
        }
    }
}
